import 'dart:convert';

class HcRegexpUtil {
  const HcRegexpUtil._();

  //验证是否是Base64
  static checkIsBase64(String str) {
    RegExp regExp = RegExp(
        r"(data:\S+/\S+;base64,)?(([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)){1}");
    bool firstCheck = customRegexp(regExp, str);
    //初步判断是否符合Base64格式
    if (!firstCheck) {
      return false;
    }
    //尝试看是否能还原成Unit8List
    try {
      const Base64Decoder().convert(str);
      return true;
    } catch (e) {
      return false;
    }
  }

  ///判断是否是数字
  static bool regIsNumber(String str) {
    RegExp exp = RegExp(r'^\d+(\.\d+)?$');
    return customRegexp(exp, str);
  }

  static bool hasChinese(String str){
    RegExp exp = RegExp(
        r"[\u4e00-\u9fa5|\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]");
    return customRegexp(exp, str);

  }

  static customRegexp(RegExp regExp, String string) {
    return regExp.hasMatch(string);
  }

}
